
//样式
import style from './style.module.less'
import cls from 'classnames'
//api
import { getAboutData } from '@/api/article';
import { recommebdList } from '@/api/article';
//组件
import BaseAbout from "coms/baseAbout";
import BaseComment from "coms/baseComment"
import BaseCard from "coms/baseCard";//推荐阅读组件
//store
import { useStore } from "@/store/Provider"
import { useNavigate } from 'react-router-dom';



const Into = () => {
    const { commentModule } = useStore();
    const navigate = useNavigate();
    // 点击 推荐阅读 跳详情
    const toDetaiil = (id) => {
        navigate(`/article/${id}`)
    }
    return (
        <div>
            {/* 左侧内容  传入调用的各自的接口*/}
            <BaseAbout
                request={async () => {
                    const { data: { data } } = await getAboutData();
                    return {
                        data
                    }
                }}
            />
            {/* 评论 */}
            <BaseComment
                pageInfo={{ // 启用分页
                    page: 1,
                    pageSize: 3,
                    size: 'small'
                }}
                request={async ({ pageConfig }) => {  // 发送请求 组件创建 分页改变
                    const { data } = await commentModule.gitMsgboard(pageConfig);
                    return {
                        data: data.data[0], // 评论数据
                        total: data.data[1]  // 评论总条数
                    }
                }}
            />
            {/* 推荐阅读 */}
            <BaseCard title="推荐阅读"
                className={cls([style.BaseCard])}
                request={async () => {
                    const { data: { data } } = await recommebdList();
                    return {
                        data
                    }
                }}
            >
                {
                    (item, index) => {
                        return <p key={index} onClick={() => toDetaiil(item.id)}>{item.title}</p>
                    }
                }
            </BaseCard>


        </div>
    )
}

export default Into;
